cmake_minimum_required(VERSION 3.4.1)

# 先把可能的旧值清掉，避免“追加”遗留
unset(RENDERER_SOURCES)
unset(RENDERER_LINK_LIBS)
unset(RENDERER_INCLUDE_DIRS)

# 只编译我们保留的这个文件
set(RENDERER_SOURCES video_renderer_webrtc.c)

# 如果你的 webrtc 渲染器需要 GStreamer/JSON-GLib/Libsoup 头文件或库，就检测并仅添加库与包含目录
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
  pkg_check_modules(GST REQUIRED
    gstreamer-1.0>=1.4
    gstreamer-sdp-1.0>=1.4
    gstreamer-video-1.0>=1.4
    gstreamer-app-1.0>=1.4
    gstreamer-webrtc-1.0>=1.14
    libsoup-3.0
    json-glib-1.0
  )
  set(RENDERER_LINK_LIBS ${RENDERER_LINK_LIBS} ${GST_LIBRARIES})
  set(RENDERER_INCLUDE_DIRS ${RENDERER_INCLUDE_DIRS} ${GST_INCLUDE_DIRS})
endif()

add_library(renderers STATIC ${RENDERER_SOURCES})
target_link_libraries(renderers ${RENDERER_LINK_LIBS})
target_include_directories(renderers PRIVATE ${RENDERER_INCLUDE_DIRS})

# 传回父作用域需要的宏定义（目前为空也没问题）
set(RENDERER_FLAGS "${RENDERER_FLAGS}" PARENT_SCOPE)
